// 6.47 编写按层次顺序（同一层自左至右）遍历二叉树的算法。
#include <stdio.h>
#include <stdlib.h>
#include "E:\Desktop\data_struct\5TREE\1_bin_tree\creat.h"

void fun_6_47(tree *root)
{
    if (root)
    {
        tree *que[100];
        int f, r;
        f = r = 0;
        que[r++] = root;
        while (f < r)
        {
            tree *t = que[f++];
            printf("%3d", t->data);
            if (t->left)
                que[r++] = t->left;
            if (t->right)
                que[r++] = t->right;
        }
    }
}

int main()
{
    /*******************code*******************/
    int n = 15;
    int a1[15] = {1,
                  2, 3,
                  4, 5, NULL, NULL,
                  NULL, 6, 7, NULL, NULL, NULL, NULL, NULL};
    tree *root;
    CreatTree(root, a1, n, 0);
    fun_6_47(root);
    /******************************************/
    printf("\n\n****************************\n");
    printf("Press Enter key to continue\n");
    getchar();
    return 0;
    /******************************************/
}
